<?php
// $Id: print.php,v 1.2.6.2 2005/01/20 21:14:58 wanikoo Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
// ------------------------------------------------------------------------- //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //

include 'header.php';

$storyid = isset($_GET['storyid']) ? intval($_GET['storyid']) : 0;
if ( empty($storyid) ) {
    redirect_header("index.php");
}

$can_qrcode = 0;
if ( $news_can_qrcode == 0 ) {
	$can_qrcode = 0;
}
else if ( $news_can_qrcode == 1) {
	$can_qrcode = 1;
}
else if ( $news_can_qrcode == 2) {
	if ( $xoopsUser ) {
	$can_qrcode =1;
	}
	else {
	$can_qrcode =0;
	}
}
else {
	$can_qrcode = 0;
}

if ( empty($can_qrcode) ) {
	die("Not allowed now!");
}

include_once XOOPSNEWSPATH.'/class/class.newsstory.php';

$article = new NewsStory($storyid);
if ( $article->published() == 0 || $article->published() > time() ) {
    redirect_header(XOOPSNEWSURL.'/index.php', 2, _NW_NOSTORY);
    exit();
}

$myts =& MyTextSanitizer::getInstance();

$article_data = $article->hometext() . $article->bodytext();
$article_title = $article->title();
$article_title = news_html2text($myts->undoHtmlSpecialChars($article_title));
$hometext = $article->hometext();
$bodytext = $article->bodytext();
$content = $myts->undoHtmlSpecialChars($hometext) . '<br /><br />' . $myts->undoHtmlSpecialChars($bodytext);
$content = str_replace("[pagebreak]","<br /><br />",$content);


function news_qrcode_convert_encoding($str, $to = 'SJIS', $from = _CHARSET) 
{
	if (function_exists('mb_convert_encoding')) {
		if (is_array($str)) {
			foreach ($str as $key=>$val) {
				$str[$key] = news_qrcode_convert_encoding($val, $to, $from);
			}
			return $str;
		} else {
			return mb_convert_encoding($str, $to, $from);
		}
	}else {
		return $str;
	}
}

function news_qrcode_encoding($data="") {
$data = news_qrcode_convert_encoding($data);
$data = rawurlencode($data);
$data = ereg_replace("%20", "+", $data);
return $data;
}

$news_data = array();
$news_data['text'] = $content;
$news_data['title'] = $article_title;
$data = $news_data['title']."\r\n".$news_data['text'];
$qrcodedata = news_qrcode_encoding($data);
$linkqrcode = "<img alt='qrcode of linkdata' title='qrcode of linkdata'src='".XOOPS_URL."/modules/qrcode/qrcode_image.php?d=$qrcodedata&amp;e=M&amp;s=4&amp;v=0&amp;t=P&amp;rgb=000000' />\n";

echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n";
echo "<html>\n<head>\n";
echo "<title>" . $xoopsConfig['sitename'] . "</title>\n";
echo "<meta http-equiv='Content-Type' content='text/html; charset=" . _CHARSET . "' />\n";
echo "<meta name='AUTHOR' content='" . $xoopsConfig['sitename'] . "' />\n";
echo "<meta name='COPYRIGHT' content='Copyright (c) ".date('Y')." by " . $xoopsConfig['sitename'] . "' />\n";
echo "<meta name='DESCRIPTION' content='" . $xoopsConfig['slogan'] . "' />\n";
echo "<meta name='GENERATOR' content='" . XOOPS_VERSION . "' />\n\n\n";
echo "<body bgcolor='#ffffff' text='#000000'>
<div style='width: 750px; border: 1px solid #000; padding: 20px;'>
<div style='text-align: center; display: block; margin: 0 0 6px 0;'>
<h2 style='margin: 0;'>".$news_data['title']."</h2></div>
<div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>
<div style='text-align: left'>".$news_data['text']."</div>
<div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>
<div style='text-align: left'>NEWS DATA QRCODE<br />".$linkqrcode."</div>
<div style='padding-top: 12px; border-top: 2px solid #ccc;'></div>
<p>From: &nbsp;".XOOPSNEWSURL."/article.php?storyid=".$storyid."</p>
</div>
<br />";
echo "<br /></body></html>";


?>